1. Technical Field
The present invention relates in general to a system and method for measuring usage of software locks in a non-intrusive manner. More particularly, the present invention relates to a system and method that collects lock information when a lock is contended with minimal or no impact on a lock when the lock is available.
2. Description of the Related Art
The operating systems and large applications are important programs that run on a computer. Every general-purpose computer has an operating system in order to run other programs. Operating systems perform basic tasks, such as recognizing input from the keyboard, sending output to the display screen, keeping track of files and directories, and controlling peripheral devices such as disk drives and printers. Important applications, such as database systems, provide services that are often used by many other applications. Operating systems and applications have many resources, such as files, data structures, and other components that are shared amongst many programs (i.e., threads) that are running simultaneously in the system.
Many operating systems and applications manage shared resources, such as files, data structures, and devices, using software latches, also known as “locks.” Software locks prevent multiple processes from each altering a storage area at almost the same time resulting in a corrupted storage value. Software locks include simple locks and complex locks. Simple locks allow one process to access the shared resource at a given time. Complex locks, on the other hand, allow either one writer or multiple readers to access the shared resource simultaneously. As the name implies, simple locks are generally simpler to implement and, as a result, are typically faster because shared resources that cannot benefit from the ability to support multiple simultaneous readers.
Conversely, complex locks are more expensive (in terms of processing requirements) than simple locks and are slow when the number of writers is great in comparison with the number of readers. However, complex locks offer a performance advantage in situations where larger numbers of processes request to read a shared resource in comparison with the number of processes requesting to update the resource. By allowing multiple readers simultaneously, complex locks can typically dispose of large numbers of readers faster than simple locks.
Processes have priorities that determine their relative accessibility to a processor. When a lower priority thread owns a lock which a higher-priority thread is attempting to acquire, the owner has its priority promoted to that of the most favored thread waiting for the lock. When the owner releases the lock, its priority is restored to its normal value. Priority promotion ensures that the lock owner can run and release its lock, so that higher priority processes or threads do not remain blocked on the lock.
Complex locks are read-write locks which protect thread-thread critical sections. Complex locks may be preemptable, meaning that a kernel thread can be preempted by another, higher priority kernel thread while it holds a complex lock. Complex locks can also be spin locks; a kernel thread which attempts to acquire a complex lock may spin (busy-wait: repeatedly execute instructions which do nothing) if the lock is not free.
One challenge with the prior art is understanding the contention for shared resources. One approach to this challenge is measuring lock usage to determine how threads are using the locks. A challenge of this approach, however, is that the process of measuring lock usage often greatly impacts system performance as metric information is recorded for each lock that is requested and acquired.
What is needed, therefore, is a system and method for measuring lock usage only when there is true contention for the lock. In this manner, intrusiveness of measuring and monitoring lock usage is minimalized and overall system performance is not unduly impacted by the measurement process.